package com.gzsxy.esjy.service.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzsxy.esjy.service.auth.dao.AuthMapper;
import com.gzsxy.esjy.service.auth.entity.User;
import com.gzsxy.esjy.service.auth.service.AuthService;
import com.gzsxy.esjy.service.base.dto.response.UserRsp;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 权限认证
 * @date 2022/2/7 15:53
 */

@Service
public class AuthServiceImpl extends ServiceImpl<AuthMapper, User> implements AuthService {


    /**
     * @description: 根据用户账号获取用户信息
     * @param username 用户账号
     * @return
     */
    @Override
    public UserRsp getByAccount(String username,String school) {

        User user = baseMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getSchool,school).eq(User::getUserName, username).or().eq(User::getPhone,username));
        if(ObjectUtils.isNotEmpty(user)){
            UserRsp userRsp = new UserRsp();
            BeanUtils.copyProperties(user,userRsp);
            return userRsp;
        } else {
            return null;
        }

    }
}
